//package com.example.ui.imageview.bigimageview;
//
//import android.graphics.Bitmap;
//import android.graphics.Canvas;
//import android.graphics.PointF;
//import android.os.Environment;
//import android.util.Log;
//import android.view.View;
//
//import com.example.lib.component.BaseActivity;
//import com.example.router.ActivityRouter;
//import com.example.xhandroidexample.R;
//
//import java.io.BufferedOutputStream;
//import java.io.File;
//import java.io.FileNotFoundException;
//import java.io.FileOutputStream;
//import java.io.IOException;
//
//@ActivityRouter(category = "自定义View",title = "大图加载以及支持滑动缩放",descript = "加载大图以及支持滑动缩放等操作")
//public class BigImageViewActivity extends BaseActivity {
//    @Override
//    protected void initOnCreate() {
//        SubsamplingScaleImageView photoView = (SubsamplingScaleImageView) findViewById(R.id.iv_pic);
//        photoView.setImage(ImageSource.uri(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + "/local1.jpg"));
//        photoView.setOnImageEventListener(new SubsamplingScaleImageView.OnImageEventListener() {
//            @Override
//            public void onReady() {
//                Log.d("xcl_debug", "onReady: ");
//                int sWidth = photoView.getSWidth();
//                Log.d("xcl_debug", "initOnCreate: sWidth = " + sWidth);
//                int sHeight = photoView.getSHeight();
//                Log.d("xcl_debug", "initOnCreate: sHeight = " + sHeight);
//
//                int dimensionPixelSize5 = getResources().getDimensionPixelSize(R.dimen.dp_500);
//                int dimensionPixelSize3 = getResources().getDimensionPixelSize(R.dimen.dp_300);
//
//                Log.d("xcl_debug", "initOnCreate: Height Scale = " + ((dimensionPixelSize5*1.0f)/(sHeight*1.0f)));
//                Log.d("xcl_debug", "initOnCreate: Width Scale = " + (dimensionPixelSize3*1.0f)/(sWidth*1.0f));
//
//                photoView.setScaleAndCenter(((dimensionPixelSize5*1.0f)/(sHeight*1.0f)),new PointF(sWidth/2.0f,sHeight/2.0f));
//                photoView.setMinScale(((dimensionPixelSize5*1.0f)/(sHeight*1.0f)));
//                photoView.setMaxScale(((dimensionPixelSize5*1.0f)/(sHeight*1.0f)));
//            }
//
//            @Override
//            public void onImageLoaded() {
//                Log.d("xcl_debug", "onImageLoaded: ");
//            }
//
//            @Override
//            public void onPreviewLoadError(Exception e) {
//                Log.e("xcl_debug", "onPreviewLoadError: ",e);
//            }
//
//            @Override
//            public void onImageLoadError(Exception e) {
//                Log.e("xcl_debug", "onImageLoadError: ",e);
//            }
//
//            @Override
//            public void onTileLoadError(Exception e) {
//                Log.e("xcl_debug", "onTileLoadError: ",e);
//            }
//
//            @Override
//            public void onPreviewReleased() {
//                Log.d("xcl_debug", "onPreviewReleased: ");
//            }
//        });
////        photoView.post(new Runnable() {
////            @Override
////            public void run() {
////                int sWidth = photoView.getSWidth();
////                Log.d("xcl_debug", "initOnCreate: sWidth = " + sWidth);
////                int sHeight = photoView.getSHeight();
////                Log.d("xcl_debug", "initOnCreate: sHeight = " + sHeight);
////
////                int dimensionPixelSize5 = getResources().getDimensionPixelSize(R.dimen.dp_500);
////                int dimensionPixelSize3 = getResources().getDimensionPixelSize(R.dimen.dp_300);
////
////                Log.d("xcl_debug", "initOnCreate: Height Scale = " + ((dimensionPixelSize5*1.0f)/(sHeight*1.0f)));
////                Log.d("xcl_debug", "initOnCreate: Width Scale = " + (dimensionPixelSize3*1.0f)/(sWidth*1.0f));
////                photoView.setScaleX(((dimensionPixelSize5*1.0f)/(sHeight*1.0f)));
////                photoView.setScaleY(((dimensionPixelSize5*1.0f)/(sHeight*1.0f)));
////            }
////        });
//        photoView.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                Bitmap drawingCache = photoView.getDrawingCache();
//                Log.d("xcl_debug", "onClick: drawingCache = " + drawingCache);
//                if (drawingCache == null) {
//                    drawingCache = Bitmap.createBitmap(photoView.getWidth(),photoView.getHeight(), Bitmap.Config.ARGB_8888);
//                    Canvas canvas = new Canvas(drawingCache);
//                    photoView.draw(canvas);
//                }
//
//                File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + "/" + System.currentTimeMillis() + ".jpg");
//
//                FileOutputStream outputStream = null;
//                BufferedOutputStream bos = null;
//                try {
//                    if (!file.exists()) {
//                        file.createNewFile();
//                    }
//                    outputStream = new FileOutputStream(file);
//                    bos = new BufferedOutputStream(outputStream);
//                    drawingCache.compress(Bitmap.CompressFormat.JPEG, 100, bos);
//                    bos.flush();
//                    Log.d("xcl_debug", "onClick: file.absolutePath = " + file.getAbsolutePath());
//                } catch (FileNotFoundException e) {
//                    e.printStackTrace();
//                } catch (IOException e) {
//                    e.printStackTrace();
//                } finally {
//                    try {
//                        outputStream.close();
//                        bos.close();
//                    } catch (IOException e) {
//                        e.printStackTrace();
//                    }
//                }
//            }
//        });
//
//        photoView.setZoomEnabled(false);
//    }
//
//    @Override
//    protected int setLayoutXmlid() {
//        return R.layout.activity_big_imageview;
//    }
//}
